﻿@using Telerik.Web.Mvc
@using Telerik.Web.Mvc.UI
@using Presentation.Web.Admin
@model  IEnumerable<Domain.Dto.SightPointCommReplyDto>
@{
    var targetId = ViewBag.id == null ? 0 : ViewBag.id;
    ViewBag.subtitle = "景点评论回复管理";
    ViewBag.title = "景点评论回复管理";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<input id = "targetId" name = "targetId" type = "hidden" value = "@(targetId)"/>
@{Html.Telerik().Grid(Model)
    .Name("SightCommReplyGrid")
    .ToolBar(toolBar => toolBar.Template(
    @<text>
    @{
        if (Html.HasUiPermission(this.ViewContext, "searchshgitcommreply"))
        {
        <label class="customer-label" for="Customers-input">
            回复内容:
        </label>
        <input type="text" id="searchSightReply" value="回复内容" data-autocomplete="/sight/searchshgitcommreply" />
        <input type='button' value='我要搜索' class='t-button' onclick='searchChange()' />        
        }
        if (Html.HasUiPermission(this.ViewContext, "muldeletesightcommreply"))
        {
        <a href='javascript:;' class='t-button' onclick='mulDelete()'>删除选择项</a> 
        }
    }
    <a href='/sight/detail/@(targetId)' class='t-button' style="float: right;">返回</a>
    </text>))
    .Columns(columns =>
    {
        columns.Template(@<text><input name="selectRow" type="checkbox" value="@item.Id " title="checkedRecords" /></text>)
        .HeaderTemplate(@<text><input type="checkbox" title="选择所有" id="checkAllRecords" /></text>)
        .Width(50).HeaderHtmlAttributes(new { style = "text-align:center" }).HtmlAttributes(new { style = "text-align:center" })
        .ClientTemplate("<input type=\"checkbox\" title=\"check all records\" name = 'selectRow' value = '<#= Id #>'/>");

        columns.Bound(o => o.Id).Width(50).Title("系统Id").Hidden();
        columns.Bound(o => o.CommId).Width(200).Title("评论景点Id").Hidden();

        columns.Bound(o => o.Contents).Width(200).Title("回复内容").HtmlAttributes(new { style = "overflow:hidden;" }).ReadOnly();
        columns.Bound(o => o.UserName).Width(100).Title("用户名").ReadOnly();

        columns.Bound(o => o.UserId).Width(200).Title("用户Id").Hidden();
        columns.Bound(o => o.IpAddress).Width(100).Title("添加IP").ReadOnly();
        columns.Bound(o => o.AddTime).Width(200).Title("添加时间").ReadOnly();
        columns.Bound(o => o.SortNum).Width(100).Title("排序号").Hidden();
        columns.Bound(o => o.State).Width(100).Title("状态").Hidden();

        columns.Command(comm =>
        {
            if (Html.HasUiPermission(this.ViewContext, "deletesightcommreply"))
            {
                comm.Delete().ButtonType(GridButtonType.Text);
            }
        }).Width(300).Title("删除");
    })
    .ClientEvents(clientEvents => clientEvents.OnDataBinding("dataBinding").OnComplete("bindComplete"))
    .DataKeys(key => key.Add("Id"))//添加主键
    .DataBinding(dataBinding => dataBinding.Ajax().Select("ajaxsightcommreplyindex", "sight")
        .Delete("deletesightcommreply", "sight", new { targetId = targetId }))
    .Pageable(page => page.PageSize(15))
    .Groupable()
    .Render();
}
<script type="text/javascript">
    function searchChange() {
        $("#SightCommReplyGrid").data("tGrid").rebind();
    }

    function dataBinding(args) {
        var searchKeyStr = $("#searchSightReply").val();
        var targetId = $('#targetId').val();
        if (searchKeyStr == '回复内容') {
            searchKeyStr = '';
        }
        args.data = $.extend(args.data, { targetId: targetId, searchKey: searchKeyStr });
    }

    function mulDelete() {
        var delStr = $(':checked , #targetId');
        if (delStr.length <= 1) {
            alert('亲，您没有选择任何记录.');
            return;
        }
        jQuery.post('/sight/muldeletesightcommreply', delStr, function (res) {
            if (res.success) {
                setTimeout(function () {
                    $("#SightCommReplyGrid").data("tGrid").rebind();
                    $("#checkAllRecords").attr("checked", false);
                }, 1000);
            } else {
                alert(res.message);
            }
        });
    }

    function bindComplete(e) {
        $("input:checkbox[name='selectRow']").attr("checked", false);
        var success = e.response.success;
        if (success != null && success != undefined) {
            alert(e.response.message);
            window.location.reload();
        }
    }

    $(function () {
        $("input:checkbox[name='selectRow']").attr("checked", false);
        $('#checkAllRecords').click(function checkAll() { $("#SightCommReplyGrid tbody input:checkbox[name='selectRow']").attr("checked", this.checked); });

        $(":input[data-autocomplete]").each(function () {
            $(this).autocomplete({
                source: function (request, response) {
                    var url = '/sight/searchshgitcommreply/';
                    $.getJSON(url, {
                        term: $.trim(request.term),
                        targetId: $('#targetId').val()
                    }, response);
                }
            });
        });

        $("#searchSightReply").focus(function () {
            if (this.value == "回复内容") {
                $("#searchSightReply").val("");
            }
        }).blur(function () {
            if (this.value == "") {
                $("#searchSightReply").val("回复内容");
            }
        });
    });
</script>
